<?php
namespace App\Services\Finance\NoticeAndPay;

use App\Models\Finance\Repair;
use App\Models\Finance\Monthstatis;
use App\Models\Finance\Pay;
use App\Models\Agent\Agent;
use App\Models\User\UsersInfo;
use App\Services\Finance\ValidateNoticeAndPay;
use App\Services\Manage\ManageIndex;
/**
 * @Author: 于婧雯
 * @Date:   2018-11-14 16:25:06
 * @Last Modified by:   ws
 * @Last Modified time: 2018-06-12 
 */
class NoticeAndPayLogic
{
    //差账管理 列表 搜索
    public function priceDifference($data)
    {
        $_where = [];
        if(!empty($data['time'])){
            $_where=['time'=>$data['time']];
        }
        $list = Repair::where($_where)
            ->orderBy('id', 'desc')
            ->paginate(10);
        return auto_success($list, '成功获取列表', '获取列表失败');
    }

    //差账管理 添加 
    public function addPriceDifference($data)
    {

        $rst = Repair::insertGetId($data);
        if ($rst === false) {
            return auto_failure($data, '添加失败！');
        } elseif ($rst === 0) {
            return auto_failure($data, '未作改动！');
        }
        return auto_return(['id' => $rst], '添加成功！');
    }

    //通知 列表
    public function financeInform($data): array
    {
        $list = Monthstatis::orderBy('id', 'desc')
            ->paginate(10);
        return auto_success($list, '成功获取列表', '获取列表失败');
    }
    //支付中心 7个统计数据
    public function financeCount($data): array
    {
        $_where1['type'] = 0;
        $_where1['status'] = 1;
        $_where2['type'] = 1;
        $_where2['status'] = 1;
        $_where3['type'] = 0;
        $_where3['status'] = 0;
        $_where4['type'] = 1;
        $_where4['status'] = 0;
        $count = [];
        $count['alwayscount1'] = Pay::where($_where1)->sum('money');
        $count['alwayscount2'] = Pay::where($_where2)->sum('money');
        $count['applycount1'] = Pay::where($_where3)->sum('money');
        $count['applycount2'] = Pay::where($_where4)->sum('money');
        $count['nocount1'] = UsersInfo::sum('money');
        $count['nocount2'] = Agent::sum('money');

        return auto_success($count, '成功获取数据', '获取数据失败');
    }

    //音乐人 已完成提现 列表
    public function alwayslist1($data): array
    {
        $_where['type'] = 0;
        $_where['status'] = 1;
        
        if (isset($data['action']) && $data['action']=='music_action1') {
            $_where['name'] = $data['name'];
        }
        //dd($_where);
        $alwayslist1 = Pay::where($_where)
            ->paginate(10);
        return auto_success($alwayslist1, '成功获取列表', '获取列表失败');
    }
    //代理 已完成提现 列表
    public function alwayslist2($data): array
    {
        $_where['type'] = 1;
        $_where['status'] = 1;
        if (isset($data['action']) && $data['action']=='agency_action1') {
            $_where['name'] = $data['name'];
        }
        $alwayslist2 = Pay::where($_where)
            ->paginate(10);
        return auto_success($alwayslist2, '成功获取列表', '获取列表失败');
    }

    //音乐人 已申请提现 列表
    public function applylist1($data): array
    {
        $_where['type'] = 0;
        $_where['status'] = 0;
        if (isset($data['action']) && $data['action']=='music_action2') {
            $_where['name'] = $data['name'];
        }
        $applylist1 = Pay::where($_where)
            ->paginate(10);
        return auto_success($applylist1, '成功获取列表', '获取列表失败');
    }
    //代理 已申请提现 列表
    public function applylist2($data): array
    {
        $_where['type'] = 1;
        $_where['status'] = 0;
        if (isset($data['action']) && $data['action']=='agency_action2') {
            $_where['name'] = $data['name'];
        }
        $applylist2 = Pay::where($_where)
            ->paginate(10);
        return auto_success($applylist2, '成功获取列表', '获取列表失败');
    }
    //音乐人 当前未提现 列表
    public function nolist1($data)
    {
        $_where = [];
        if (isset($data['action']) && ($data['action']=='music_action3' || $data['action']=='music_action4')) {
            $_where['real_name'] = $data['name'];
        }
        $nolist1 = UsersInfo::where('money', '<>', 0)->where($_where)
            ->paginate(10);
        return auto_success($nolist1, '成功获取列表', '获取列表失败');
    }
    //代理 当前未提现 列表
    public function nolist2($data)
    {
        $_where = [];
        if (isset($data['action']) && ($data['action']=='agency_action3' || $data['action']=='agency_action4')) {
            $_where['payee_name'] = $data['name'];
        }
        $nolist2 = Agent::where('money', '<>', 0)->where($_where)
            ->paginate(10);
        return auto_success($nolist2, '成功获取列表', '获取列表失败');
    }

    //获取支付中心数据（无分页,导出excel用）
    public function payListNoPage()
    {
        $list = Pay::select('id', 'name', 'band_card', 'money', 'type', 'created_at', 'deal_time')->get()->toArray();
        return auto_success($list);
    }
   
}